var token = []

const start = char => {
    if (char === '0' || char === '1' || char === '2' || char === '3'
        || char === '4' || char === '5' || char === '6' || char === '7'
        || char === '8' || char === '9'
    ) {
        token.push(char)
        return isnumber
    }
    if (char === '+' || char === '-' || char === '*' || char === '/') {
        emitToken(char, char)
        return start
    }
    if (char === ' ' || char === '\r' || char === '\n') {
        return start
    }
    emitToken('EOF')
}

const isnumber = char => {
    if (char === '0' || char === '1' || char === '2' || char === '3'
        || char === '4' || char === '5' || char === '6' || char === '7'
        || char === '8' || char === '9'
    ) {
        token.push(char)
        return isnumber
    } else {
        emitToken('Number', token.join(''))
        token = []
        return start(char)
    }
}

let tokens = []
const emitToken = (type, value) => tokens.push({type, value})

const parse = str => {
    tokens = []
    let state = start
    for (let c of str) {
        state = state(c)
    }
    state(Symbol('EOF'))
    return tokens
}

module.exports = parse
